﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace FriendsNearby.Services.Tests
{
    [TestFixture]
    public class TextHelperFixture
    {
        [Test]
        public void ShouldPluralize0Friends()
        {
            Assert.AreEqual("no friends", "0 friend".Pluralize());
        }

        [Test]
        public void ShouldPluralize1Friends()
        {
            Assert.AreEqual("1 friend", "1 friend".Pluralize());
        }

        [Test]
        public void ShouldPluralize5Friends()
        {
            Assert.AreEqual("5 friends", "5 friend".Pluralize());
        }

        [Test]
        public void ShouldPluralizeFriendsWithWrappingText()
        {
            Assert.AreEqual(
                "result: no friends in your area.",
                "result: 0 friend in your area.".Pluralize());
        }

        [Test]
        public void ShouldNotPluralizeFriendPrefix()
        {
            Assert.AreEqual(
                "result: 0 friendship in your area.",
                "result: 0 friendship in your area.".Pluralize());
        }

        [Test]
        public void ShouldPluralize0Person()
        {
            Assert.AreEqual("no people", "0 person".Pluralize());
        }

        [Test]
        public void ShouldPluralize1Person()
        {
            Assert.AreEqual("1 person", "1 person".Pluralize());
        }

        [Test]
        public void ShouldPluralize15Person()
        {
            Assert.AreEqual("15 people", "15 person".Pluralize());
        }

        [Test]
        public void ShouldPluralizePeopleWithWrappingText()
        {
            Assert.AreEqual(
                "result: 20 people in your area.",
                "result: 20 person in your area.".Pluralize());
        }

        [Test]
        public void RelativeDateTimeStringReturnsNowIfTimeInFuture()
        {
            Assert.AreEqual("now", TextHelper.FormatDateTimeRelativeToNow(DateTime.Now.Add(new TimeSpan(1, 1, 1))));
        }

        [Test]
        public void RelativeDateTimeStringReturnsNowIfTimeIsLessThanAMinute()
        {
            Assert.AreEqual("now", TextHelper.FormatDateTimeRelativeToNow(DateTime.Now.Subtract(new TimeSpan(0, 0, 59))));
        }

        [Test]
        public void RelativeDateTimeStringReturnsRoundedMinutesIfTimeIsLessThanAnHour()
        {
            Assert.AreEqual("3 minutes ago", TextHelper.FormatDateTimeRelativeToNow(DateTime.Now.Subtract(new TimeSpan(0, 2, 59))));
        }

        [Test]
        public void RelativeDateTimeStringReturnsRoundedMinutesIfTimeIsLessThanAnHourTwoDigits()
        {
            Assert.AreEqual("20 minutes ago", TextHelper.FormatDateTimeRelativeToNow(DateTime.Now.Subtract(new TimeSpan(0, 20, 15))));
        }

        [Test]
        public void RelativeDateTimeStringReturnsRoundedHoursIfTimeIsLessThanADay()
        {
            Assert.AreEqual("3 hours ago", TextHelper.FormatDateTimeRelativeToNow(DateTime.Now.Subtract(new TimeSpan(3, 2, 59))));
        }

        [Test]
        public void RelativeDateTimeStringReturnsRoundedHoursIfTimeIsLessThanADayTwoDigits()
        {
            Assert.AreEqual("20 hours ago", TextHelper.FormatDateTimeRelativeToNow(DateTime.Now.Subtract(new TimeSpan(19, 50, 15))));
        }

        [Test]
        public void RelativeDateTimeStringReturnsRoundedDaysIfTimeIsLessThan2Weeks()
        {
            Assert.AreEqual("10 days ago", TextHelper.FormatDateTimeRelativeToNow(DateTime.Now.Subtract(new TimeSpan(10, 3, 2, 59))));
        }

        [Test]
        public void RelativeDateTimeStringReturnsRoundedWeeksIfTimeIsLessThanaMonth()
        {
            Assert.AreEqual("2 weeks ago", TextHelper.FormatDateTimeRelativeToNow(DateTime.Now.Subtract(new TimeSpan(15, 3, 2, 59))));
        }

        [Test]
        public void RelativeDateTimeStringReturnsRoundedMonthsIfTimeIsLessThanaYear()
        {
            Assert.AreEqual("8 months ago", TextHelper.FormatDateTimeRelativeToNow(DateTime.Now.Subtract(new TimeSpan(8 * 30, 3 * 30, 2 * 30, 30))));
        }

        [Test]
        public void RelativeDateTimeStringReturnsRoundedYearsIfTimeIsMoreThan365Days()
        {
            Assert.AreEqual("2 years ago", TextHelper.FormatDateTimeRelativeToNow(DateTime.Now.Subtract(new TimeSpan(2 * 300, 3 * 30, 2 * 30, 30))));
        }
       
    }
}
